package com.zyj.springboothapim.controller;


import com.zyj.springboothapim.bean.Parking;
import com.zyj.springboothapim.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//这个是默认json接收和发送@RestController
@RequestMapping("/Parking")
public class ParkingController {
    ParkingService parkingService;

    @Autowired
    public void setParkingService(ParkingService parkingService)
    {
        this.parkingService = parkingService;
    }

    //获取停车位parking_table所有信息
    @RequestMapping(value = "/selectParking" ,method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public List<Parking> selectParking(){
        System.out.println("/Parking/selectParking");
        return parkingService.selectParking();
    }

    //查询parking_table的属性park_static=“流动”的停车位信息

    @RequestMapping(value = "/selectMobileparking" ,method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public List<Parking> selectMobileparking(){
        System.out.println("/Parking/selectMobileparking");
        return parkingService.selectMobileparking();
    }

    //查询parking_table的属性park_static=“固定”的停车位信息
    @RequestMapping(value = "/selectFixedParkingSpace" ,method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public List<Parking> selectFixedParkingSpace(){
        System.out.println("/Parking/selectFixedParkingSpace");
        return parkingService.selectFixedParkingSpace();
    }

    //9.申请停车位信息到parking_table
    @RequestMapping(value = "/applyParking",method = RequestMethod.POST)
    @ResponseBody
    public String applyParking(@RequestBody Parking parking)
    {
        /*
        * 具体会在service实现查看车位是否被占用，若被占用就申请失败
        * success 申请成功
        * fall 申请失败
        * */
        String returnStr = parkingService.updataParking(parking);
        return returnStr;
    }
}
